# ifndef __GarminTdb_H_
# define __GarminTdb_H_

//
// (c) Konstantin Galichsky (kg@infratel.com), 2002-2004
// Garmin and MapSource are registered trademarks or trademarks of Garmin Ltd. or one of its subsidiaries.
//

# ifdef _MSC_VER
#	pragma pack (push, 1)
# endif

struct CTdbRecordHdr {
	// Type of the record:
	// 'P' - product definition (see CTdbProduct)
	// 'D' - copyright strings (see CTdbCopyright)
	// 'R' - (optional) ? trademarks ?
	// 'B' - overview map (see CTdbImgRef)
	// 'L' - detail map (see CTdbImgRef)
	// 'T' - (optional) ? tail ?
	BYTE btType;
	// Number of bytes in the record (except this header).
	WORD wLen;
};

///////////////////////////

struct CTdbProduct : public CTdbRecordHdr {
	/*
	The unique ID for the map collection (used as MapSource registry key)

		1   Cont US (US R&R)
		2   Hawaii  (US R&R)
		3   Alaska  (US R&R)
		5   Worldmap
		6   US Topo
		13  R&R GreatBritain
		14  R&R Germany         326 *
		15
		16  R&R Italy           260 *
		17  MG  France           12 *
		18  MG  BENELUX
		19  MG  Germany          16 *
		20  MG  Italy             8 *
		21  MG  Denmark & Sweden
		22  MG  Austria           3 *
		23  MG  Switzerland      15 *
		24  MG  SPAIN
		25  R&R France          425 *
		26  R&R Benelux         150 *
		27 
		28  R&R Austria          68 *
		29  R&R Switzerland      41 *
		30  R&R Spain           187 *

		31  Cont US (US Waterways)
		32  Hawaii  (US Waterways)
		33  Alaska  (US Waterways)
		37  Canada
	*/
	DWORD dwProductId;

	WORD  dwVer; 	// 300=Version 3.00

	// Product name in menu of MapSource and GPS
	char  strName [1];
};

struct CTdbProduct2 {
	WORD wDataVer; // 200=Version 2.00

	// Product name in MapSource's 'Product Info' box.
	char strCDSetName [1]; 
};

///////////////////////////

struct CTdbCopyright {
	BYTE btType;   // 06 for strings or 07 for logo path
	WORD wOrdinal; // 1-based, in any order (MapSource sorts copyright strings by this value)
	BYTE btMask;   // 00 for strings or 0F for logo path

	char strText [1];
};

struct CTdbCopyrights : public CTdbRecordHdr {
	CTdbCopyright c0;
};

///////////////////////////

struct CTdbReg {
	BYTE btOrdinal; // 1-based?
	char strText [1];
};

struct CTdbRegs : public CTdbRecordHdr {
	CTdbReg r0;
};

///////////////////////////

struct CTdbImgRef : public CTdbRecordHdr {
	DWORD dwImgId;

	/*
		0002e630 = 01900xx = CONT US (xx=00 bis 48)
		000900b0 = 0590000 = Worldmap(5)
		0016bc50 = 1490000 = R&R Germany(14)
		0019c990 = 1690000 = R&R Italy(16)
		0022f150 = 2290000 = MG  Austria(22)
		00278530 = 2590000 = R&R France(25)
		00290bd0 = 2690000 = R&R Benelux(26)
		002c1910 = 2890000 = R&R Austria(28)
		002d9fb0 = 2990000 = R&R Switzerland(29)
		002f2650 = 3090000 = R&R Spain(30)
	*/
	DWORD dwLandId;

	// In Garmin 32-bit units.
	LONG  lNorth;
	LONG  lEast;
	LONG  lSouth;
	LONG  lWest;

	char strDisplayName [1];
};

struct CTdbImgRef2 {
	WORD w0;

	WORD wCount; // Items in dwSectionSize[]
	DWORD dwSectionSize [1]; // Strict order: RGN, TRE, LBL, NET, NOD etc

	// BYTE btEnd; // always 0x1 ?
};

	// NOTE: optional
struct CTdbImgRef3 {
	DWORD dw0; // 0x01
	WORD w0;   // 0x00

	char strSubFileName [1] [13];

	// WORD wEnd; // always 0x00 ?
};

////////////////////////////

struct CTdbTail : public CTdbRecordHdr {
	// ??
	// 41 78 74 03 46 43 2B 47 28 B8 F0 94 DA 2F 6F EA 75 59 0B F1
};

# ifdef _MSC_VER
#	pragma pack (pop)
# endif

# endif // __GarminTdb_H_